#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

int port =6789;

int main(int argc, char ** argv)
{
	printf("starting epolll udp server\n");
	
	unsigned int sin_len;
	char message[256];
	int socket_desc;
	struct sockaddr_in sin;
	printf("Waiting data from sender...\n");

	bzero(&sin, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = htonl(INADDR_ANY);
	sin.sin_port = htons(port);
	sin_len = sizeof(sin);

	socket_desc = socket(AF_INET, SOCK_DGRAM, 0);
	bind(socket_desc, (struct sockaddr*)&sin, sin_len);

	while(1)
	{
		recvfrom(socket_desc, message, sizeof(message), 0, (struct sockaddr*)&sin, &sin_len);
		printf("Received message: %s\n", message);

		if (strncmp(message, "quit", 4) == 0)
		{
			printf("quit\n");
			break;
		}
	}
	close(socket_desc);
	return 0;
}
